package com.airlines.base.config.response;

import org.apache.commons.lang3.StringUtils;

/**
 * @author luanqing
 * @date 2018年09月10日 
 * @description ResponseResult 建造器
 * @see com.airlines.config.ResponseResult<T>
 */
public class ResponseResultBuilder {
	private static final  String SUCCESS_MESSAGE="接口调用成功";
	private static final  String SUCCESS_ERROR="接口调用失败";
	/**
	 *  正确返回
	 * @param data
	 * @param message
	 * @return
	 */
	public static <T> ResponseResult<T> successResult(T data,String message){  
        ResponseResult<T> result = new ResponseResult<>();  
        result.setData(data);  
        result.setSuccess(true);  
        if(StringUtils.isEmpty(message)){
        	message = SUCCESS_MESSAGE;
        }
        result.setMessage(message);  
        return result;  
    }  
	/**
	 * 简单的正确返回信息
	 * @return
	 */
	public static <T> ResponseResult<T> successResult(){  
        ResponseResult<T> result = new ResponseResult<>();  
        result.setData(null);  
        result.setSuccess(true);  
        result.setMessage(SUCCESS_MESSAGE);  
        return result;  
    }  
	
	/**
	 * 错误返回
	 * @param data
	 * @param message
	 * @return
	 */
	public static <T> ResponseResult<T> errorResult(T data,String message,String errorCode){  
        ResponseResult<T> result = new ResponseResult<>();  
        result.setData(data);  
        result.setSuccess(false);  
        if(StringUtils.isEmpty(message)){
        	message = SUCCESS_ERROR;
        }
        result.setMessage(message);  
        result.setErrorCode(errorCode);
        return result;  
    }  
	
	/**
	 * 简单的错误返回
	 * @param data
	 * @param message
	 * @param errorCode
	 * @return
	 */
	public static <T> ResponseResult<T> errorResult(){  
		ResponseResult<T> result = new ResponseResult<>();  
        result.setData(null);  
        result.setSuccess(false);  
        result.setMessage(SUCCESS_ERROR);  
        return result;  
    }  
}
